﻿<%@ Page Title="" Language="C#" MasterPageFile="~/master/Home.Master" AutoEventWireup="true"
    CodeBehind="address.aspx.cs" Inherits="TripsLogic.address" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
    <script type="text/javascript" src="https://maps.google.com/maps/api/js?sensor=false&amp;language=en&amp;region=DK&amp;libraries=places"></script>
    <script type="text/javascript">

        var address;
        function autoinitialize() {
            // Create the autocomplete object, restricting the search
            // to geographical location types.
            address = new google.maps.places.Autocomplete(
            /** @type {HTMLInputElement} */(document.getElementById('content_txtAddress')),
      { types: ['geocode'] });

        }

        function geolocate() {
            if (navigator.geolocation) {
                navigator.geolocation.getCurrentPosition(function (position) {
                    var geolocation = new google.maps.LatLng(
          position.coords.latitude, position.coords.longitude);
                    address.setBounds(new google.maps.LatLngBounds(geolocation,
          geolocation));
                });
            }
        }



        function addAddress() {
            jQuery('#content_contactform').show();
            jQuery('#content_divAddDelete').hide();
            return false;
        }

        function cancelAddSaveAddress() {
            jQuery('#content_contactform').hide();
            jQuery('#content_divAddDelete').show();
            return false;
        }

        function check_uncheck(Val) {
            var ValChecked = Val.checked;
            var ValId = Val.id;
            var frm = document.forms[0];
            // Loop through all elements
            for (i = 0; i < frm.length; i++) {
                // Look for Header Template's Checkbox
                //As we have not other control other than checkbox we just check following statement
                if (this != null) {
                    if (ValId.indexOf('CheckAll') != -1) {
                        // Check if main checkbox is checked,
                        // then select or deselect datagrid checkboxes
                        //alert(frm.elements[i].id);
                        // alert(frm.elements[i].id.substr(frm.elements[i].id.length - 9, frm.elements[i].id.length - 1));
                        if (frm.elements[i].id.indexOf('deleteRec') != -1)
                            if (ValChecked)
                                frm.elements[i].checked = true;
                            else
                                frm.elements[i].checked = false;
                }
                else if (ValId.indexOf('deleteRec') != -1) {
                    //alert(document.getElementById('grdProduct_ct102_CheckAll'));
                    // Check if any of the checkboxes are not checked, and then uncheck top select all checkbox
                    document.getElementById('content_dgrAddress_CheckAll').checked = false;
                    if (frm.elements[i].checked == false)
                        frm.elements[1].checked = false;
                }
            } // if
        } // for
    } // function</PRE>

    function confirmMsg(frm) {
        // loop through all elements
        for (i = 0; i < frm.length; i++) {
            // Look for our checkboxes only
            if (frm.elements[i].name.indexOf('deleteRec') != -1) {
                // If any are checked then confirm alert, otherwise nothing happens
                if (frm.elements[i].checked)
                    return confirm('Do you want to delete?')
            }
        }
    }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="content" runat="server">
    <article id="content">
				<div class="wrapper pad_bot2">
					<section class="grid_24" >
						<h2><asp:Literal ID="litAddressManager" runat="server"></asp:Literal></h2>
						<asp:Literal ID="litAddressManagerDesc" runat="server"></asp:Literal><br />
                         <div id="frmResponse" runat="server" visible="false">
                               <asp:Label ID="lblfrmResponse" runat="server"></asp:Label>
                            </div>
                            <br />
                         
                        <asp:DataGrid ID="dgrAddress" runat="server" AutoGenerateColumns="False" AllowPaging="True"
                                        CssClass="tablegrid" Font-Bold="False" Font-Italic="False" Font-Overline="False"
                                        Font-Strikeout="False" Font-Underline="False" 
                                        oneditcommand="dgrAddress_EditCommand" 
                                        onpageindexchanged="dgrAddress_PageIndexChanged" PageSize="20">
                                        <Columns>
                                            <asp:TemplateColumn HeaderText="NO.">
                                                <ItemTemplate>
                                                    <%# Container.DataSetIndex + 1%>
                                                </ItemTemplate>
                                                <HeaderStyle Font-Bold="True" Font-Italic="False" Font-Overline="False" Font-Strikeout="False"
                                                    Font-Underline="False" HorizontalAlign="Center" Width="5%" />
                                                <ItemStyle Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False"
                                                    Font-Underline="False" HorizontalAlign="Center" />
                                            </asp:TemplateColumn>
                                            <asp:BoundColumn DataField="ID" HeaderText="Id" Visible="False"></asp:BoundColumn>
                                            <asp:BoundColumn DataField="ALIAS" HeaderText="ALIAS">
                                                <HeaderStyle Font-Bold="True" Font-Italic="False" Font-Overline="False" 
                                                    Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Center"  Width="25%" />
                                                <ItemStyle Font-Bold="False" Font-Italic="False" Font-Overline="False" 
                                                    Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Left" />
                                            </asp:BoundColumn>
                                              <asp:BoundColumn DataField="FullAddress" HeaderText="FULL ADDRESS">
                                                <HeaderStyle Font-Bold="True" Font-Italic="False" Font-Overline="False" 
                                                    Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Center" />
                                                <ItemStyle Font-Bold="False" Font-Italic="False" Font-Overline="False" 
                                                    Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Left" Width="60%" />
                                            </asp:BoundColumn>
                                            <asp:EditCommandColumn CancelText="Cancel" EditText="..." UpdateText="Update">
                                            <HeaderStyle  Width="6%" HorizontalAlign="Center"/>
                                            <ItemStyle HorizontalAlign="Center"/>
                                            </asp:EditCommandColumn>
                                            <asp:TemplateColumn>
                                                <HeaderStyle Font-Bold="True" Font-Italic="False" Font-Overline="False" Font-Strikeout="False"
                                                    Font-Underline="False" HorizontalAlign="Center" />
                                                <HeaderTemplate>
                                                    <asp:CheckBox ID="CheckAll" onclick="return check_uncheck (this);" runat="server" />
                                                </HeaderTemplate>
                                                <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                                                <ItemTemplate>
                                                    <asp:CheckBox ID="deleteRec" onclick="return check_uncheck (this);" runat="server" />
                                                </ItemTemplate>
                                            </asp:TemplateColumn>
                                        </Columns>
                                        <PagerStyle Mode="NumericPages" />
                                    </asp:DataGrid>
                                          <p id="divAddDelete" runat="server" style="padding-top:15px;">
                                          <asp:LinkButton ID="lbtAddAddress" class="button1" ClientIDMode="Static" UseSubmitBehavior="false" OnClientClick="return addAddress();" runat="server"></asp:LinkButton>
                                          <asp:LinkButton ID="lbtDeleteAddress" class="button1"  Style="margin-left: 15px;" 
                                                  CausesValidation="False" OnClientClick="return confirmMsg(this.form)" 
                                                  ClientIDMode="Static" runat="server" onclick="lbtDeleteAddress_Click"></asp:LinkButton>
                                    </p>

									<div id="contactform" class="main-contacts" runat="server" style="display: none;padding-top:15px;" >
                                    	<h2><asp:Literal ID="litAddEditAddress" runat="server"></asp:Literal></h2>
						<asp:Literal ID="litAddEditAddressDesc" runat="server"></asp:Literal><br /><br />
                         <asp:HiddenField ID="hdfId" runat="server" />
                         <div class="rowElem">
														<span class="label"><asp:Literal ID="litAlias" runat="server"></asp:Literal>:</span>
														<div class="bg">
															<asp:TextBox ID="txtAlias" Width="261px"  runat="server"></asp:TextBox>   &nbsp;  &nbsp;   
                                                            
														</div>
													</div>

													<div class="rowElem">
														<span class="label"><asp:Literal ID="litAddress" runat="server"></asp:Literal>:</span>
														<div class="bg">
															<asp:TextBox ID="txtAddress" onfocus="geolocate()" Width="361px"  runat="server"></asp:TextBox>   &nbsp;  &nbsp;   
                                                            <asp:RequiredFieldValidator ID="reqValAddress" Display="Dynamic" runat="server"   ControlToValidate="txtAddress" ForeColor="Red"></asp:RequiredFieldValidator>
														</div>
													</div>
                                                      
                                                        <div class="rowElem">
														<span class="label">&nbsp;</span>
														<div class="bg">
															    <asp:LinkButton ID="lbtSave" style="float:left;" class="button1" runat="server" 
                                                        onclick="lbtSave_Click"></asp:LinkButton>
                                                        <asp:LinkButton ID="lbtCancel" Style="margin-left: 15px;float:left;"   OnClientClick="return cancelAddSaveAddress();" class="button1" runat="server"></asp:LinkButton>
														</div>

													</div>

                                                   
											</div>
						
						
					</section>
				</div>
			</article>
    </div>
</asp:Content>
